package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述:77. 组合
 *
 * @author Madison You
 * @created 0:55
 */
public class Mid_77_Combine {
    public static void main(String[] args) {
        new Mid_77_Combine().combine(4, 2);
    }

    List<List<Integer>> list = new ArrayList<>();

    List<Integer> temp = new ArrayList<>();

    public List<List<Integer>> combine(int n, int k) {
        back(n, k , 1);
        return list;
    }

    private void back(int n, int k , int u) {
        if (temp.size() == k) {
            list.add(new ArrayList<>(temp));
            return;
        }
        for (int i = u; i <= n; i++) {
            temp.add(i);
            back(n, k , i + 1);
            temp.remove(temp.size() - 1);
        }
    }
}
